package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import com.itheima.service.impl.ClazzServiceimpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    //添加班级
    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz){
        clazzService.addClazz(clazz);
        return Result.success();
    }
    //分页查询
    @GetMapping
    public Result selectClazzPage(ClazzQueryParam clazzQueryParam){
        PageBean pageBean = clazzService.selectClazzPage(clazzQueryParam);
       return Result.success(pageBean);
    }
    //查询全部
    @GetMapping("/list")
    public Result selectClazzAll(){
        List<Clazz> list =clazzService.selectClazzAll();
        return Result.success(list);
    }
    //根据id删除
    @DeleteMapping("/{id}")
    public Result deleteClazzById(@PathVariable Integer id){
        clazzService.deleteClazzById(id);
        return Result.success();
    }
    //根据id查询
    @GetMapping("/{id}")
    public Result selectClazzById(@PathVariable Integer id){
        Clazz list= clazzService.selectClazzByid(id);
        return Result.success(list);
    }
    //修改班级信息
    @PutMapping
    public Result updateClazzById(@RequestBody Clazz clazz){
        System.out.println(clazz);
        clazzService.updateClazz(clazz);
        return Result.success();
    }

}
